<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <meta name="theme-color" content="#001529" />
    <meta name="description" content="智能人体行为识别系统 - 基于AI的实时人体行为分析平台" />
    <meta name="keywords" content="AI, 人体识别, 行为分析, 智能安防, 实时监控" />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <title>智能人体行为识别系统</title>
  </head>
  <body>
    <noscript>您需要启用JavaScript才能运行此应用。</noscript>
    <div id="root"></div>
    <!-- 引入AI智能体 -->
    <script src="https://agi-dev-platform-web.bj.bcebos.com/ai_apaas/embed/output/embedLiteSDK.js?responseExpires=0"></script>
    <script>
      // 定义全局变量用于存储AI实例
      let embedSDK = null;

      function initAI() {
        try {
          console.log('初始化AI智能体...');
          embedSDK = new EmbedLiteSDK({
            appId: '090ad40d-14d6-4a6f-bb47-01f4be4d9543',
            code: 'embedxbmgXT5vvd1T2PI96Pfy'
          });
          
          // 将实例存储到全局变量
          window.AI_INSTANCE = embedSDK;
          
          console.log('AI智能体初始化成功');
          window.dispatchEvent(new CustomEvent('ai-ready'));
        } catch (error) {
          console.error('AI智能体初始化失败:', error);
          window.dispatchEvent(new CustomEvent('ai-error', { detail: error }));
        }
      }

      // 提供打开对话窗口的方法
      window.openAIChat = function(message) {
        try {
          console.log('尝试打开AI对话窗口...');
          if (!embedSDK) {
            initAI();
          }
          
          if (embedSDK) {
            // 如果有消息，先发送消息
            if (message) {
              console.log('发送消息:', message);
              embedSDK.sendMessage(message);
            }
          } else {
            console.error('AI实例不存在');
            throw new Error('AI智能体未初始化');
          }
        } catch (error) {
          console.error('打开AI对话窗口失败:', error);
        }
      };

      // 页面加载完成后初始化
      if (document.readyState === 'complete') {
        initAI();
      } else {
        window.addEventListener('load', initAI);
      }
    </script>
  </body>
</html> 